tag := $(shell git describe --exact-match --tags 2>/dev/null)

branch := $(shell git rev-parse --abbrev-ref HEAD)
commit := $(shell git rev-parse --short=8 HEAD)
goarch := $(shell go env GOARCH)
goos := $(shell go env GOOS)
build_time := $(shell date '+%Y-%m-%dT%H:%M:%S')
version := $(shell echo ${version})

ifndef tag
tag := ${commit}
endif

ifndef version
version := ${tag}
endif

LDFLAGS :=  '-s -w \
            -X "gitee.com/smewl13/beehive/cmd.TIME=${build_time}" \
			-X "gitee.com/smewl13/beehive/cmd.ARCH=${goarch}" \
			-X "gitee.com/smewl13/beehive/cmd.OS=${goos}" \
			-X "gitee.com/smewl13/beehive/cmd.VERSION=${version}" \
			-X "gitee.com/smewl13/beehive/cmd.BRANCH=${branch}" \
			-X "gitee.com/smewl13/beehive/cmd.TAG=${tag}" \
			-X "gitee.com/smewl13/beehive/cmd.COMMIT=${commit}"'

.PHONY: help
help:
	@echo 'Targets:'
	@echo '  encrypt             - 编译加密工具'
	@echo '  puship              - 编译获取公网IP,并邮件或企业微信通知'
	@echo '  watchmen            - 编译磁盘守护'

.PHONY: encrypt
encrypt:
	CGO_ENABLED=0 \
	GOARCH=${goarch} \
	GOOS=${goos} \
	go build -ldflags ${LDFLAGS} \
	-o beehive-encrypt \
	./cmd/encrypt

.PHONY: puship
puship:
	CGO_ENABLED=0 \
	GOARCH=${goarch} \
	GOOS=${goos} \
	go build -ldflags ${LDFLAGS} \
	-o beehive-puship \
	./cmd/puship

.PHONY: watchmen
watchmen:
	CGO_ENABLED=0 \
	GOARCH=${goarch} \
	GOOS=${goos} \
	go build -ldflags ${LDFLAGS} \
	-o beehive-watchmen \
	./cmd/watchmen
